class Solution
{
public:
    bool matchReplacement(string s, string sub, vector<vector<char>> &mappings)
    {
        unordered_map<char, unordered_set<char>> charMap;
        for (auto &mapping : mappings)
        {
            charMap[mapping[0]].insert(mapping[1]);
        }
        int n = s.size();
        int m = sub.size();
        for (int i = 0; i <= n - m; ++i)
        {
            bool match = true;
            for (int j = 0; j < m; ++j)
            {
                if (!(sub[j] == s[i + j] || charMap[sub[j]].count(s[i + j])))
                {
                    match = false;
                    break;
                }
            }
            if (match)
            {
                return true;
            }
        }
        return false;
    }
};